package com.gzxx.controller;

import com.gzxx.domain.dto.UserChangePwdDto;
import com.gzxx.domain.dto.SysLoginDto;
import com.gzxx.domain.vo.IndexVo;
import com.gzxx.service.SysLoginService;
import com.gzxx.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author MAX
 * @date 2020/7/24 12:34 下午
 * 系统登录
 */
@Api(tags = "系统登录相关接口")
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysLoginController {

    private final SysLoginService sysLoginService;

    @PostMapping("/doLogin")
    @ApiOperation("系统登录")
    public ServerResponse login(@RequestBody SysLoginDto sysLoginDto) {
        return sysLoginService.login(sysLoginDto);
    }

    /**
     * 首页
     */
    @PostMapping("/index")
    @ApiOperation("系统首页")
    public ServerResponse index() {
        IndexVo indexVo = sysLoginService.index();
        return ServerResponse.success(indexVo);
    }

    /**
     * 生成验证码
     */
    @GetMapping("/captcha")
    @ApiOperation("生成验证码")
    public ServerResponse captcha() {
        return sysLoginService.captcha();
    }

    /**
     * 修改密码
     */
    @PostMapping("/change/password")
    @ApiOperation("修改用户密码")
    public ServerResponse changePwd(@Valid @RequestBody UserChangePwdDto dto) {
        return sysLoginService.changePwd(dto);
    }
}
